﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System .Data .SqlClient ;


public partial class Complaints : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void TextBox4_TextChanged(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection cn = new SqlConnection();
        String str;

        str = DropDownList2.SelectedValue.ToString();
        str = str + "=" + "'" + IDTextBox.Text + "'";

        cn.ConnectionString = ConfigurationManager.ConnectionStrings["PAS_DB"].ConnectionString;
        String query = "select * from CitizenRecord where " + str;
        SqlCommand cmd = new SqlCommand(query, cn);
        cn.Open();
        SqlDataReader dr = cmd.ExecuteReader();
        if (!dr.Read())
        {
            Response.Redirect("CustomError1.aspx");
        }
        else
        {
            SqlConnection con = new SqlConnection();
            con.ConnectionString = ConfigurationManager.ConnectionStrings["PAS_DB"].ConnectionString;
            query = "select max(ComNo)from CompTab";
            SqlCommand cm = new SqlCommand(query, con);
            con.Open();
            SqlDataReader rd = cm.ExecuteReader();
            int compid;
            if (!rd.Read())
            {
                compid = 0;
            }
            else
            {
                compid = (int)rd[0] + 1;
            }
            con.Close();
            SqlConnection conn = new SqlConnection();
            conn.ConnectionString = ConfigurationManager.ConnectionStrings["PAS_DB"].ConnectionString;
            SqlCommand command = new SqlCommand("insert into CompTab values(@comno, @fname, @lname, @gender, @citizenIDType, @citizenID, @fathersName, @addLine1, @addCity, @addState, @zipCode, @mobile, @email, @report)", con);
            command.Parameters.AddWithValue("@comno", compid);
            command.Parameters.AddWithValue("@fname", nametb.Text);
            command.Parameters.AddWithValue("@lname", TextBox2.Text);
            command.Parameters.AddWithValue("@gender", RadioButtonList1.SelectedValue.ToString());
            command.Parameters.AddWithValue("@citizenIDType", DropDownList2.SelectedIndex);
            command.Parameters.AddWithValue("@citizenID", IDTextBox.Text);
            command.Parameters.AddWithValue("@fathersName", FnameTb.Text);
            command.Parameters.AddWithValue("@addLine1", addTextBox.Text);
            command.Parameters.AddWithValue("@addCity", CityTB.Text);
            command.Parameters.AddWithValue("@addState", stateDropDownList1.SelectedItem.ToString());
            command.Parameters.AddWithValue("@zipCode", ZipTB.Text);
            command.Parameters.AddWithValue("@mobile", TextBox10.Text);
            command.Parameters.AddWithValue("@email", TextBox12.Text);
            command.Parameters.AddWithValue("@report", TextBox15.Text);

            con.Open();
            int i = command.ExecuteNonQuery();
            if (i > 0)
            {
                Label21.Text = "Registered! Complaint Number is " + compid;
            }
            conn.Close();

        }
    }
}

